package com.xiaojf.xfile.configure;

import com.xiaojf.xfile.configure.props.LocalFileStorageProperties;
import com.xiaojf.xfile.configure.props.XfileProperties;
import com.xiaojf.xfile.service.FileService;
import com.xiaojf.xfile.service.impl.LocalFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文件服务配置
 *
 * @author Ade.Xiao 2021/4/10 10:33
 */
@Configuration
@EnableConfigurationProperties({XfileProperties.class, LocalFileStorageProperties.class})
public class XfileConfigure {
    @Autowired
    private LocalFileStorageProperties localFileStorageProperties;

    /**
     * 初始化本地文件存储服务
     *
     * @return {@link FileService}
     * @author Ade.Xiao 2021-04-10 10:49:38
     */
    @Bean
    @ConditionalOnProperty(prefix = "xfile", name = "storage-type", havingValue = "LOCAL", matchIfMissing = true)
    public FileService fileService() {
        return new LocalFileServiceImpl(localFileStorageProperties);
    }
}
